/**
 * Copyright (c) 2018 软唐 All rights reserved.
 *
 * https://www.softtown.cn
 *
 * 版权所有，侵权必究！
 */

package com.softtown.modules.dapai.controller;

import com.github.pagehelper.PageInfo;
import com.softtown.common.utils.ConvertUtils;
import com.softtown.common.utils.Result;
import com.softtown.modules.dapai.dto.CompMacAddDTO;
import com.softtown.modules.dapai.dto.CompMacDTO;
import com.softtown.modules.dapai.dto.CompMacDetailDTO;
import com.softtown.modules.dapai.entity.CompMacEntity;
import com.softtown.modules.dapai.service.CompMacService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @Author: Ding Ya Yong
* @Description: 设备
* @date: 2022/1/2 20:47
* @Param:
* @return:
*/
@RestController
@RequestMapping("mac")
@Api(tags="设备")
public class CompMacController {

    @Resource
    private CompMacService compMacService;

    @PostMapping("getMacPageList")
    @ApiOperation("获取设备分页")
    public Result getMacPageList(@RequestBody CompMacDTO compMacDTO) {
        PageInfo<CompMacDTO> compMacDTOPageInfo = compMacService.getMacPageList(compMacDTO);
        return new Result<PageInfo<CompMacDTO>>().ok(compMacDTOPageInfo);
    }



    @PostMapping("getMacById")
    @ApiOperation("获取设备详情")
    public Result<CompMacEntity> getMacById(@RequestBody CompMacDTO compMacDTO) {
        CompMacAddDTO compMacAddDTO = compMacService.getMacById(compMacDTO.getCompId(),compMacDTO.getId());
        return new Result<CompMacEntity>().ok(compMacAddDTO.getCompMacEntity());
    }


    @PostMapping("addMac")
    @ApiOperation("添加设备")
    public Result addMac(@RequestBody CompMacEntity compMacEntity) {
        Result result = new Result<>();
        CompMacAddDTO compMacAddDTO = new CompMacAddDTO();
        compMacAddDTO.setCompMacEntity(compMacEntity);
        compMacService.addMac(compMacAddDTO);
        return result;
    }

    @PostMapping("updateMac")
    @ApiOperation("修改设备")
    public Result updateMac(@RequestBody CompMacEntity compMacEntity) {
        Result result = new Result<>();
        CompMacAddDTO compMacAddDTO = new CompMacAddDTO();
        compMacAddDTO.setCompMacEntity(compMacEntity);
        compMacService.updateMac(compMacAddDTO);
        return result;
    }

    @PostMapping("deleteMac")
    @ApiOperation("删除设备")
    public Result deleteMac(@RequestBody CompMacDTO compMacDTO) {
        Result result = new Result<>();
        compMacService.deleteMac(compMacDTO);
        return result;
    }


    @PostMapping("listForMac")
    @ApiOperation("下拉框获取设备")
    public Result listForMac(@RequestBody CompMacDTO compMacDTO) {
        List<CompMacDTO> compMacDTOList = compMacService.listForMac(compMacDTO);
        return new Result<List<CompMacDTO>>().ok(compMacDTOList);
    }

}
